package com.chenfan.mcn.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chenfan.mcn.annotations.ActionTracing;
import com.chenfan.mcn.constant.NumberCst;
import com.chenfan.mcn.extension.Res;
import com.chenfan.mcn.model.StarBillingHeader;
import com.chenfan.mcn.service.StarBillingHeaderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 红人开票信息
 * @Author liuyang
 * @Date 2021/12/10
 * @Time 10:47
 * @Version V1.0
 **/
@Slf4j
@RestController
@RequestMapping("/star/billing")
public class StarBillingHeaderController {

    @Autowired
    private StarBillingHeaderService starBillingHeaderService;


    /**
     * 修改启用状态
     *
     * @param id     id
     * @param status 状态
     * @return boolean
     */
    @ActionTracing("修改状态")
    @GetMapping("/enable/status")
    public Res<Boolean> modifyEnableStatus(Long id, Integer status) {
        return Res.ok(starBillingHeaderService.modifyEnableStatus(id, status));
    }


    /**
     * 根据开票抬头获取红人开票信息
     *
     * @param starId     红人id
     * @param headerName 抬头名称
     * @return 开票抬头信息
     */
    @GetMapping("/getBillingHeader")
    public Res<StarBillingHeader> getBillingHeader(Long starId, String headerName) {
        return Res.ok(starBillingHeaderService.getBillingHeader(starId, headerName));
    }


    /**
     * 删除红人开票信息
     *
     * @param id id
     * @return Boolean
     */
    @GetMapping("/delete")
    public Res<Boolean> delete(Long id) {
        return Res.ok(starBillingHeaderService.delete(id));
    }

    /**
     * 获取红人对应的开票信息
     * @param starId 红人ID
     * @param status 状态 0-启用，1-禁用
     * @return
     */
    @GetMapping("/getStarBillingHeaderList")
    public Res<List<StarBillingHeader>> getStarBillingHeaders(@RequestParam(name ="starId") Long starId, @RequestParam(name ="status", required = false) Integer status) {
        return Res.ok(starBillingHeaderService.selectList(Wrappers.lambdaQuery(StarBillingHeader.class)
                .eq(StarBillingHeader::getStarId, starId)
                .eq(Objects.nonNull(status), StarBillingHeader::getIsEnable, status)
                .eq(StarBillingHeader::getIsDelete, NumberCst.ZERO)));
    }
}
